<?php
namespace Seller\Model;
class OrderModel extends CommonModel{
    
    protected $tableName = 'order';
    
    protected $_link = array(
        'Order_line' => array(
            'mapping_type' => self::HAS_MANY,
            'class_name' => 'Order_line',
            'foreign_key' => 'order_id',
            'mapping_name' => 'order_line',
            'mapping_order' => 'create_time desc',
        // 定义更多的关联属性
        ),
        'Order_payment' => array(
            'mapping_type' => self::HAS_ONE,
            'class_name' => 'Order_payment',
            'foreign_key' => 'order_id',
            'mapping_name' => 'order_payment',
//            'mapping_order' => 'create_time desc',
        // 定义更多的关联属性
        ),
    );

    function __construct($name = '', $tablePrefix = '', $connection = '') {
        parent::__construct($name, $tablePrefix, $connection);
    }
    
    //产品列表
    public function getList($where = array(), $order = array('o.id'=>"DESC")) {
        //开始分页信息
        $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
        $count = $this->alias('o')->where($where)->count();
        //分页
        $pagesize = 20; #每页数量
        $offset = $pagesize * ($p - 1); //计算记录偏移量
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $limit = $offset . ',' . $pagesize;
        $list = $this->alias('o')->where($where)->order($order)->limit($limit)->field('o.*')->select();
        if( $lists ) {
            foreach( $lists as $key => $value ) {
                //获得来源平台名称
                $lists[$key]['platform_name'] = M('customer_platform_bind')->where(array('id' => $value['platform_id']))->getField('name');
            }
        }
        $arr = array('count' => $count, 'list' => $list, 'page' => $page,);
        return $arr;
    }
}